//
//  QRCodeScanOverlayerDiscover.m
//  Staff
//
//  Created by jing zhao on 3/31/16.
//
//

#import "QRCodeScanOverlayerDiscover.h"
#import "NotificationDefine.h"


@implementation QRCodeScanOverlayerDiscover

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self = [[NSBundle mainBundle] loadNibNamed:@"QRCodeScanOverlayerDiscover" owner:self options:nil].lastObject;
    }
    return self;
}

- (void)awakeFromNib {
    
    [super awakeFromNib];

    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
    CGAffineTransform transform2 = CGAffineTransformMakeRotation(M_PI);
    CGAffineTransform transform3 = CGAffineTransformMakeRotation(-M_PI/2);
    topRight.transform = transform;
    bottemRight.transform = transform2;
    bottemLeft.transform = transform3;
//    [self sendSubviewToBack:bottomView];
//    navBar.backgroundColor = [UIColor darkGrayColor];
    scanView.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width-scanView.frame.size.width)/2, scanView.frame.origin.y, scanView.frame.size.width, scanView.frame.size.height);
    
    CGFloat viewWidth = [UIScreen mainScreen].bounds.size.width;
    
    UIView *navBar = [[UIView alloc] initWithFrame:CGRectMake(0, 20, viewWidth, 44)];
    navBar.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
    [self addSubview:navBar];
    
    UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    closeButton.backgroundColor = [UIColor clearColor];
    [closeButton setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
    closeButton.frame = CGRectMake(2, 2, 40, 40);
    //[closeButton setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        closeButton.frame = CGRectMake(2, 2, 40, 40);
    }
    
    [closeButton addTarget:self action:@selector(closeNofity) forControlEvents:UIControlEventTouchUpInside];
    [navBar addSubview:closeButton];
    
    CGFloat labelX =closeButton.frame.origin.x+closeButton.frame.size.width +10;
    
    UILabel *titleTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX,closeButton.frame.origin.y,viewWidth- 2*labelX,closeButton.frame.size.height)];
    titleTextLabel.backgroundColor = [UIColor clearColor];
    titleTextLabel.textColor = [UIColor whiteColor];
    titleTextLabel.textAlignment = NSTextAlignmentCenter;
    titleTextLabel.font = [UIFont systemFontOfSize:20];
    titleTextLabel.text = @"Scan";
    [navBar addSubview:titleTextLabel];
}


-(void)closeNofity{
    [[NSNotificationCenter defaultCenter]postNotificationName:NotificationScanCancel object:nil];
}
- (IBAction)tapCheckAr:(id)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:NotificationScanCheck object:nil];
}
@end
